import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:flutter_first_one/get_controller/count.dart';

class Create extends StatefulWidget {
  const Create({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _CreateState createState() => _CreateState();
}

class _CreateState extends State<Create> {
  // get.find 找到全局状态对象
  CountController countController = Get.find();

  List<String> items = List.generate(1, (index) => "Item $index");
  Future<void> _refreshList() async {
    // 模拟数据刷新的异步操作
    await Future.delayed(Duration(seconds: 2));

    setState(() {
      items = List.generate(20, (index) => "New Item $index");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('儿时故事'),
      ),
      body: RefreshIndicator(
        onRefresh: _refreshList,
        child: ListView.builder(
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text(items[index]),
              subtitle: Obx(() => Text(countController.count.toString())),
            );
          },
        ),
      ),
    );
  }
}
